package com.hup.utils.io.batch.constant;

import com.hup.utils.commons.interfaces.BaseConstant;
import lombok.Getter;

/**
 * window服务的启动类型
 */
public enum WinServiceStartType implements BaseConstant {
    UNKNOWN("未知", -1, "未知", "未知", 0),
    /**
     * 对字符串匹配顺序有要求, [延迟]要在[自动]之前!
     */
    AUTO_START_DELAYED("自动(延迟启动)", 2, "AUTO_START  (DELAYED)", "delayed-auto", 1),
    AUTO_START("自动", 2, "AUTO_START", "auto", 2),
    DEMAND_START("手动", 3, "DEMAND_START", "demand", 3),
    DISABLED("禁用", 4, "DISABLED", "disabled", 4),;

    /**
     * [服务管理器]下的[启动类型]
     */
    @Getter
    public final String desc;
    /**
     * [sc qc]的[START_TYPE]字段结果int
     * @deprecated 自动和延迟自动都是2,不能区分意义
     */
    public final int scQcType;
    /**
     * [sc qc]的[START_TYPE]字段结果String
     */
    public final String scQcTypeName;
    /**
     * [sc config start]的启动类型指令,<boot|system|auto|demand|disabled|delayed-auto>
     */
    public final String scConfigTypeCmd;
    /**
     * 注册表中[start]的字段取值
     */
    public final int regStartType;

    WinServiceStartType(String desc, int scQcType, String scQcTypeName, String scConfigTypeCmd, int regStartType) {
        this.desc = desc;
        this.scQcType = scQcType;
        this.scQcTypeName = scQcTypeName;
        this.scConfigTypeCmd = scConfigTypeCmd;
        this.regStartType = regStartType;
    }

    @Override
    public String toString() {
        return desc;
    }

    /**
     * 根据批处理运行结果,某行获取启动类型
     */
    public static WinServiceStartType getByCmdResp(String line) {
        for (WinServiceStartType val : values()) {
            if (line.contains(val.scQcTypeName)) {
                return val;
            }
        }
        return UNKNOWN;
    }
}